package com.sun.springmvc.demo.controller;

import com.sun.springmvc.demo.service.IDemoService;
import com.sun.springmvc.frmework.annotaations.SunAutoWired;
import com.sun.springmvc.frmework.annotaations.SunController;
import com.sun.springmvc.frmework.annotaations.SunRequestMapping;
import com.sun.springmvc.frmework.annotaations.SunSecurity;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@SunRequestMapping("/sun")
@SunController
public class DemoController {

    @SunAutoWired
    private IDemoService service;

    @SunRequestMapping("/java")
    @SunSecurity({"zhangsan","lisi"})
    public void getJavaInfo(HttpServletRequest r, HttpServletResponse b, String username) throws IOException {
        String name = service.getJavaInfo(username);
        b.setCharacterEncoding("UTF-8");
        b.setHeader("Content-type","text/html;charset=UTF-8");
        b.getWriter().write(name);
    }

    @SunRequestMapping("/android")
    @SunSecurity("admin")
    public void getAndroidInfo(HttpServletRequest r, HttpServletResponse b, String username) throws IOException {
        String name = service.getAndroidInfo(username);
        b.setCharacterEncoding("UTF-8");
        b.setHeader("Content-type","text/html;charset=UTF-8");
        b.getWriter().write(name);
    }

    @SunRequestMapping("/ios")
    @SunSecurity("wangwu")
    public void getIosInfo(HttpServletRequest r, HttpServletResponse b, String username) throws IOException {
        String name = service.getIosInfo(username);
        b.setCharacterEncoding("UTF-8");
        b.setHeader("Content-type","text/html;charset=UTF-8");
        b.getWriter().write(name);
    }

    @SunRequestMapping("/react")
    @SunSecurity("zhaoliu")
    public void getReactInfo(HttpServletRequest r, HttpServletResponse b, String username) throws IOException {
        String name = service.getReactInfo(username);
        b.setCharacterEncoding("UTF-8");
        b.setHeader("Content-type","text/html;charset=UTF-8");
        b.getWriter().write(name);
    }

}
